import axios from 'axios';

const API_URL = 'http://map.shader.show/drugadmin/public/index.php?s=interactive/';

const apiClient = axios.create({
	baseURL: API_URL,
	headers: {
		'Content-Type': 'application/json',
	},
});

apiClient.interceptors.request.use(config => {
	const token = localStorage.getItem('token');
	if (token) {
		config.headers.Authorization = `Bearer ${token}`;
	}
	return config;
});

const MakeAPIParam = (data = {}) => {
	return {
		data: data,
		meta: {
			user_id: localStorage.getItem("uid") || "",
			token: localStorage.getItem("token") || "",
		}
	};
};


export default {
	login(credentials) {
		return apiClient.post('user/login', MakeAPIParam(credentials));
	},
	getActiveQuestion(id){
		return apiClient.post('user/getActiveQuestion',MakeAPIParam({id:id}));
	},
	uploadAnswerHistory(activeId,isRight){
		return apiClient.post('user/uploadAnswerHistory',MakeAPIParam({activeId:activeId,answerRight:isRight}))
	},
	getActiveList(){
		return apiClient.post('user/getActiveList',MakeAPIParam());
	},
	getExchange(){
		return apiClient.post('user/exchangeGift',MakeAPIParam());
	}
};